package cn.lili.modules.promotion.entity.dos;

import cn.lili.common.utils.StringUtils;
import cn.lili.mybatis.model.BaseStandardEntity;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;

import java.sql.Time;
import java.util.Date;

/**
 * @author:xiangqian
 * @date: 2024/4/17 9:08
 */
@Data
@TableName("li_advertising")
@ApiModel(value = "广告")
public class Advertising extends BaseStandardEntity {

    @ApiModelProperty(value = "标题")
    private String title;

    @ApiModelProperty(value = "内容")
    private String content;

    @ApiModelProperty(value = "图片")
    private String picture;

    @ApiModelProperty(value = "链接")
    private String link;

    @ApiModelProperty(name = "生效时间", notes = "")
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date effectiveTimeBegin;

    @ApiModelProperty(name = "失效时间", notes = "")
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date effectiveTimeEnd;

    @ApiModelProperty(name = "显示开始时间", notes = "")
    @JsonFormat(timezone = "GMT+8", pattern = "HH:mm:ss")
    @DateTimeFormat(pattern = "HH:mm:ss")
    private Time revealTimeBegin;

    @ApiModelProperty(name = "显示结束时间", notes = "")
    @JsonFormat(timezone = "GMT+8", pattern = "HH:mm:ss")
    @DateTimeFormat(pattern = "HH:mm:ss")
    private Time revealTimeEnd;

    @ApiModelProperty(value = "显示频率")
    private String revealFrequency;

    @ApiModelProperty(value = "显示频率描述")
    private String revealFrequencyRemark;

    @ApiModelProperty(value = "状态")
    private String status;

    @ApiModelProperty(value = "广告位ID")
    private String spaceId;


    @TableField(exist = false)
    @ApiModelProperty(name = "创建开始时间", notes = "")
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date createTimeBegin;

    @TableField(exist = false)
    @ApiModelProperty(name = "创建结束时间", notes = "")
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date createTimeEnd;

    /**
     * 构建分页查询条件
     * */
    public LambdaQueryWrapper<Advertising> queryWrapperPage() {
        LambdaQueryWrapper<Advertising> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.like(StringUtils.isNotEmpty(this.title), Advertising::getTitle, this.title);
        lambdaQueryWrapper.like(StringUtils.isNotEmpty(this.status), Advertising::getStatus, this.status);
        //显示时间
        lambdaQueryWrapper.gt(this.revealTimeBegin != null, Advertising::getRevealTimeBegin, this.revealTimeBegin)
                .lt(this.revealTimeEnd != null, Advertising::getRevealTimeEnd, this.revealTimeEnd);
        //创建时间
        lambdaQueryWrapper.gt(this.createTimeBegin != null, Advertising::getCreateTime, this.createTimeBegin)
                .lt(this.createTimeEnd != null, Advertising::getCreateTime, this.createTimeEnd);
        return lambdaQueryWrapper;
    }
}
